//
//  ZYMainViewController.swift
//  weibo007
//
//  Created by 陈宗毅 on 15/12/15.
//  Copyright © 2015年 czy. All rights reserved.
//

import UIKit

class ZYMainViewController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = ZYMainTabbar()
        
        setValue(mainTabBar, forKey: "tabBar")
        
    
        //准备闭包
        mainTabBar.composeBtnClick = {() -> () in
        
        let controller = ZYComposeViewController()
            self.presentViewController(UINavigationController(rootViewController: controller), animated: true, completion: nil)

        }

        //首页
        let homeVC = ZYHomeViewController()
        self.addChildVC(homeVC, title: "首页", imageName: "tabbar_home")
        //消息
        let messageVC = ZYMessageViewController()
        self.addChildVC(messageVC, title: "消息", imageName: "tabbar_message_center")
        //发现
        let discoveryVC = ZYDiscoveryViewController()
        self.addChildVC(discoveryVC, title: "发现", imageName: "tabbar_discover")
        //我
        let profileVC = ZYProfileViewController()
        self.addChildVC(profileVC, title: "我", imageName: "tabbar_profile")

    }
  

        private func addChildVC(controller:UIViewController,title:String,imageName:String)
        {
            //包装导航控制器
            self.addChildViewController(UINavigationController(rootViewController: controller))
            //设置title,导航栏和tabBar
            controller.title = title
            //设置图片
            controller.tabBarItem.image = UIImage(named: imageName)
            //设置高亮图片
            let highLightedName = imageName + "_highlighted"
            controller.tabBarItem.selectedImage = UIImage(named: highLightedName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            //设置文字颜色
            controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState:UIControlState.Selected)
        }
    
}
